Skip to content

Fix GH-23956: Regression with MySQL 4.1 after mysqlnd security fix - #24432

Open
jeroenvdkolff wants to merge 1 commit into
php:PHP-8.4from
jeroenvdkolff:fix-gh-23956
Open

jeroenvdkolff wants to merge 1 commit into
php:PHP-8.4from
jeroenvdkolff:fix-gh-23956

Conversation

@jeroenvdkolff

Copy link
Copy Markdown

Fixes GH-23956

Since the fix for GHSA-r6x9-5r99-36j7, PHP can no longer run queries on a MySQL 4.1 server. You get "Premature end of data" and "EOF packet shorter than expected".

Cause

MySQL 4.1 sometimes sends an EOF packet of only 1 byte. The code already has a branch to handle this (the else in php_mysqlnd_eof_read()). But the new check BAIL_IF_NOT_ENOUGH_DATA after p++ requires at least 2 bytes. The old BAIL_IF_NO_MORE_DATA did not require that. So that branch can no longer be reached.

The same happens in php_mysqlnd_auth_response_read() with a 1-byte 0xFE packet. There it only adds two extra warnings before the normal "old insecure authentication" error.

Fix

I moved the check into the ERROR_MARKER branch, because that is the only branch that reads more data. The other checks from the security fix are not changed.

Tests

  • Two new fake-server tests: gh23956.phpt (1-byte EOF) and gh23956_2.phpt (1-byte auth response). Both fail without the fix and pass with it.
  • All existing fake-server tests still pass, including all ghsa-r6x9-5r99-36j7-* tests.
  • I also tested against a real MySQL 4.1.11 server (Docker image oblakstudio/mysql41). Queries, prepared statements and PDO work again. With the full ext/mysqli and ext/pdo_mysql test suites, 421 tests that failed before no longer fail. Six tests could not run before, because their SKIPIF crashed on this bug. Now they run, but fail because of MySQL 4.1 limitations (no SSL, older SQL syntax, older transaction behaviour). This does not affect modern MySQL or MariaDB versions.

Note

I am not a C developer, and I made this fix with help from an AI assistant. I did test it myself, as described above. I am happy to change anything, or to move the PR to another branch if needed.

The fix for GHSA-r6x9-5r99-36j7 made 1-byte EOF and auth switch packets
fail the length check after reading the first byte. MySQL 4.1 sends such
packets. Only require more data in the error branch, which actually
reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant